
package cn.touna.jss.modules.third.zhima.client;

import cn.touna.jss.common.properties.disconf.ZhimaProperties;
import cn.touna.jss.modules.third.zhima.entity.AccreditDto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.antgroup.zmxy.openplatform.api.DefaultZhimaClient;
import com.antgroup.zmxy.openplatform.api.request.ZhimaAuthInfoAuthqueryRequest;
import com.antgroup.zmxy.openplatform.api.response.ZhimaAuthInfoAuthqueryResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * <P>查询芝麻授权client</P>
 *
 * @author tianhuaxing 2017年5月22日 下午8:01:32
 * @since 1.0.0.000
 */
@Component
public class GetAuthWatchlistGetClient {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ZhimaProperties zhimaProperties;

    /**
     * 查询授权信息
     */
    public ZhimaAuthInfoAuthqueryResponse zhimaAuthInfoReq(AccreditDto accreditQueryDto) throws Exception {
        ZhimaAuthInfoAuthqueryRequest req = new ZhimaAuthInfoAuthqueryRequest();
        ZhimaAuthInfoAuthqueryResponse response = null;
        req.setAuthCategory("C2B");
        req.setIdentityType(zhimaProperties.getIdentityType());// 必要参数
        Map<String, String> identityParams = new HashMap<String, String>();
        identityParams.put("businessId", "touna");
        identityParams.put("certNo", accreditQueryDto.getIdCard());
        identityParams.put("name", accreditQueryDto.getName());
        identityParams.put("certType", zhimaProperties.getCertType());
        req.setIdentityParam(JSONObject.toJSONString(identityParams));
        DefaultZhimaClient client = new DefaultZhimaClient(zhimaProperties.getGatewayUrl(), zhimaProperties.getAppId(),
                zhimaProperties.getPrivateKey(), zhimaProperties.getZhimaPublicKey());
        response = client.execute(req);
        logger.info("【查询芝麻授权】芝麻返回结果:{}", JSON.toJSON(response));
        return response;
    }
}